package com.zhxy.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一返回结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class R {

    // 返回结果状态码
    private int code;

    // 结果消息
    private String msg;

    // 结果数据
    private Object data;

    // 成功
    public static R OK(){
        return R.builder()
                .code(CodeEnum.OK.getCode())
                .msg(CodeEnum.OK.getMsg())
                .build();
    }

    public static R OK(int code,String msg){
        return R.builder()
                .code(code)
                .msg(msg)
                .build();
    }

    public static R OK(Object data){
        return R.builder()
                .code(CodeEnum.OK.getCode())
                .msg(CodeEnum.OK.getMsg())
                .data(data)
                .build();
    }

    public static R OK(CodeEnum codeEnum){
        return R.builder()
                .code(codeEnum.getCode())
                .msg(codeEnum.getMsg())
                .build();
    }

    // 失败
    public static R FALL(){
        return R.builder()
                .code(CodeEnum.OK.getCode())
                .msg(CodeEnum.OK.getMsg())
                .build();
    }

    public static R FALL(int code,String msg){
        return R.builder()
                .code(code)
                .msg(msg)
                .build();
    }

    public static R FALL(String msg){
        return R.builder()
                .code(CodeEnum.FALL.getCode())
                .msg(msg)
                .build();
    }

    public static R FALL(CodeEnum codeEnum){
        return R.builder()
                .code(codeEnum.getCode())
                .msg(codeEnum.getMsg())
                .build();
    }
}
